from api_qiyeweixin.apis.wework import WeWork
from api_qiyeweixin.untils.tool import save_jsonshema


class DepartmentApi(WeWork):

    def create_dep(self, create_dict: dict):
        create_dict.setdefault("method", "POST")
        r = self.send_api("create", create_dict)

        return r

    def delete_dep(self, delete_id):
        delete_dict = {
            "method": "GET",
            "params": {
                "id": delete_id
            }
        }
        r = self.send_api("delete", delete_dict)

        return r

    def update_dep(self, update_dict: dict):
        update_dict.setdefault("method", "POST")
        r = self.send_api("update", update_dict)

        return r

    def list_dep(self, select_id=None):
        select_dict = {"method": "GET"}
        if select_id:
            select_dict.setdefault("params", {"id": select_id})

        r = self.send_api("list", select_dict)

        return r


if __name__ == '__main__':
    r = DepartmentApi().list_dep()
    save_jsonshema("department.json", r.json())
